﻿<UserControl x:Class="EpiDashboard.RowFilterControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:EpiDashboard="clr-namespace:EpiDashboard"
             mc:Ignorable="d" FontSize="16" FontFamily="Global User Interface">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="StyleDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" DockPanel.Dock="Bottom">
        <StackPanel>
        <Grid Name="grdAll" HorizontalAlignment="Center" VerticalAlignment="Top" >
            <StackPanel x:Name="panelBasic">
                <StackPanel x:Name="friendlyCondition">
                    <Grid Name="grdSelectionProperties" Grid.Row="0" HorizontalAlignment="Left" Visibility="Visible">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock x:Name="tblockValueFieldName" HorizontalAlignment="Left" TextAlignment="Center" Margin="5, 5, 5, 5" Text="The value of Field Name:" Grid.Row="0" Grid.Column="0" />
                        <!--<ListBox x:Name="lbxConditions" HorizontalAlignment="Left" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" Width="514" Visibility="Collapsed"/>-->



                        <ComboBox x:Name="cmbFieldName" Margin="5, 5, 5, 5" HorizontalAlignment="Left" SelectedIndex="0" Grid.Row="0" Grid.Column="1" MaxWidth="210" Width="210" SelectionChanged="cmbFieldName_SelectionChanged" />

                        <TextBlock x:Name="tblockOperator" HorizontalAlignment="Left" TextAlignment="Center" Text="Operator:" Margin="5, 5, 5, 5"  Grid.Row="1" Grid.Column="0"  />
                        <ComboBox x:Name="cmbOperator" Margin="5, 5, 5, 5" HorizontalAlignment="Left" SelectedIndex="0" Grid.Row="1" Grid.Column="1" MaxWidth="210" Width="210" SelectionChanged="cmbOperator_SelectionChanged" />

                        <!--Single value controls-->
                        <TextBlock x:Name="txtValue" HorizontalAlignment="Left" TextAlignment="Center" Text="Value:" Margin="5, 5, 5, 5"  Grid.Row="3" Grid.Column="0"  />
                        <TextBlock x:Name="txtLoValue" HorizontalAlignment="Left" TextAlignment="Center" Text="Low Value:" Margin="5, 5, 5, 5"  Grid.Row="3" Grid.Column="0" Visibility="Hidden"  />
                        <ComboBox x:Name="cmbValue" Margin="5, 5, 5, 5"  HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210"  IsEditable="True" Grid.ColumnSpan="3"/>
                            <DatePicker x:Name="dpValue" Margin="5, 5, 5, 5" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210" Visibility="Visible">
                                <DatePicker.Resources>
                                    <Style TargetType="Button">
                                        <Setter Property="MaxHeight" Value="30" />
                                    </Style>
                                </DatePicker.Resources>
                            </DatePicker>
                            <TextBox x:Name="tbxNumericValue" Margin="5, 5, 5, 5" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210"   Visibility="Visible" PreviewTextInput="tbxNumericValue_PreviewTextInput" />
                        <TextBox x:Name="tbxValue" Margin="5, 5, 5, 5" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210"   Visibility="Visible" />

                        <!--Between Lo and Hi value controls -->
                        <TextBox x:Name="tbxLowValue" Margin="5, 5, 5, 5"  HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210"  Visibility="Visible" PreviewTextInput="tbxNumericValue_PreviewTextInput" />
                            <DatePicker x:Name="dpLowValue" Margin="5, 5, 5, 5" HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" MaxWidth="210" Width="210"  Visibility="Visible">
                                <DatePicker.Resources>
                                    <Style TargetType="Button">
                                        <Setter Property="MaxHeight" Value="30" />
                                    </Style>
                                </DatePicker.Resources>
                            </DatePicker>

                            <TextBlock x:Name="txtAnd" Visibility="Visible" Text="and" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="4"/>

                        <TextBlock x:Name="txtHiValue" HorizontalAlignment="Left" TextAlignment="Center" Text="High value:" Margin="5, 5, 5, 5"  Grid.Row="5" Grid.Column="0"  />
                        <TextBox x:Name="tbxHighValue" Margin="5, 5, 5, 5"  HorizontalAlignment="Left" Grid.Row="5" Grid.Column="1" MaxWidth="210" Width="210"  Visibility="Visible" PreviewTextInput="tbxNumericValue_PreviewTextInput" />
                            <DatePicker x:Name="dpHighValue" Margin="5, 5, 5, 5" HorizontalAlignment="Left" Grid.Row="5" Grid.Column="1" MaxWidth="210" Width="210"  Visibility="Visible">
                                <DatePicker.Resources>
                                    <Style TargetType="Button">
                                        <Setter Property="MaxHeight" Value="30" />
                                    </Style>
                                </DatePicker.Resources>
                            </DatePicker>

                            <Button x:Name="btnNewCondition" Width="Auto" IsEnabled="False" MinWidth="155" Height="32" Grid.ColumnSpan="2" Grid.Row="6" HorizontalAlignment="Left" Click="btnNewCondition_Click">
                            <Button.Content>
                                <Label x:Name="tblockAddThisCondition">Add this condition</Label>
                            </Button.Content>
                            <Button.ContextMenu>
                                <ContextMenu>
                                    <MenuItem x:Name="mnuAddWithAnd" Header="Add Condition with AND" Click="mnuAddWithAnd_Click" />
                                    <MenuItem x:Name="mnuAddWithOr" Header="Add Condition with OR" Click="mnuAddWithOr_Click" />
                                </ContextMenu>
                            </Button.ContextMenu>
                        </Button>
                    </Grid>
                </StackPanel>
                <TextBlock x:Name="tblockDataFilterListHeading" HorizontalAlignment="Left" TextAlignment="Center" Text="Data filters:" Margin="0,5,0,0" Grid.Row="5" Grid.Column="0" />
                <DataGrid x:Name="dgFilters" 
                                      HorizontalAlignment="Stretch" 
                                      HorizontalScrollBarVisibility="Hidden" 
                                      Grid.Row="6" 
                                      Grid.Column="0" 
                                      Grid.ColumnSpan="6" 
                                      CanUserReorderColumns="False" 
                                      CanUserResizeColumns="True" 
                                      CanUserResizeRows="False" 
                                      CanUserSortColumns="False" 
                                      CanUserAddRows="False" 
                                      CanUserDeleteRows="False" 
                                      IsReadOnly="True" SelectionMode="Single"
                                      Height="200"/>
                <!--<StackPanel x:Name="panelAdvanced" Visibility="Collapsed" Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="3" >
                <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Record processing scope:" Grid.ColumnSpan="2"/>
                <ComboBox x:Name="cbxRecordProcessScope" HorizontalAlignment="Left" MaxWidth="140" Width="140" IsEditable="False" Grid.ColumnSpan="3" SelectionChanged="cbxRecordProcessScope_SelectionChanged" />
            </StackPanel>-->

                <Grid x:Name="grdGuidedModeButtons" VerticalAlignment="Top" Grid.Row="2" Margin="0, 10, 0, 0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <Button x:Name="btnRemoveCondition" Width="Auto" MaxWidth="200" MinWidth="100" Height="Auto" Margin="5,0,5,0" HorizontalAlignment="Left" Click="btnRemoveCondition_Click">
                        <Button.Content>
                            <Label x:Name="tblockRemoveSelected">Remove selected</Label>
                        </Button.Content>
                    </Button>
                    <Button x:Name="btnClearConditions" Width="Auto" MaxWidth="200" MinWidth="100" Height="Auto" Margin="5,0,5,0" Grid.Column="1" HorizontalAlignment="Left" Click="btnClearConditions_Click">
                        <Button.Content>
                            <Label x:Name="tblockClearAllConditions">Clear all conditions</Label>
                        </Button.Content>
                    </Button>
                    <Button x:Name="btnAdvancedMode" Width="Auto" MaxWidth="200" MinWidth="100" Height="Auto" Margin="5,0,5,0" Grid.Column="2" HorizontalAlignment="Left" IsEnabled="False" Click="btnAdvancedMode_Click" >
                        <Button.Content>
                            <Label x:Name="tblockAdvancedMode">Advanced mode</Label>
                        </Button.Content>
                    </Button>
                </Grid>
            </StackPanel>

            <StackPanel Grid.Row="4" x:Name="pnlAdvancedMode" VerticalAlignment="Top" Margin="20, 0, 0, 0" Visibility="Collapsed">
                <TextBlock x:Name="tblockAdvanceFilterMode" Text="Advanced Filter " FontWeight="Bold" Margin="0, 0, 0, 3" />
                <TextBlock x:Name="txtDesiredDataFilter" Text="Type the desired data filter string into the text box below. Several examples are provided:" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left"
                               Margin="0, 0, 0, 3" />

                <TextBlock x:Name="txtNumericData" Text="  1. Numeric data:   (AGE &gt;= 15) AND (AGE &lt;= 45)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                <TextBlock x:Name="txtTextData" Text="  2. Text data:   (LastName LIKE '%sen') OR (LastName = 'Smith')" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                <TextBlock x:Name="txtDateData" Text="  3. Date data:   (DOB &gt;= #01/01/2000#) AND (DOB &lt;= #12/31/2000 23:59:59#)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                <TextBlock x:Name="txtBooleanData" Text="  4. Boolean data:   (ILL = true)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />


                <TextBox x:Name="txtAdvancedFilter" Margin="0, 5, 0, 0" Height="40" TextWrapping="Wrap" MaxWidth="516" TextChanged="txtAdvancedFilter_TextChanged" />
                <TextBox x:Name="txtAdvancedFilterStatus" IsReadOnly="True" Margin="0, 5, 0, 0" TextWrapping="Wrap" />

                <Grid x:Name="grdAdvancedModeButtons">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="140"/>
                        <ColumnDefinition Width="140"/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="10" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="20" />
                    </Grid.RowDefinitions>
                    <Button x:Name="btnApplyAdvancedFilter" Grid.Row="1" Grid.Column="0" Width="120" Content="Apply" HorizontalAlignment="Left" Click="btnApplyAdvancedFilter_Click" />
                    <Button x:Name="btnGuidedMode"          Grid.Row="1" Grid.Column="1" Width="120" Content="Guided" Click="btnAdvancedMode_Click" HorizontalAlignment="Left" />
                </Grid>


            </StackPanel>
        </Grid>
        </StackPanel>
    </ScrollViewer>
</UserControl>
